package com.tyxy.edu.info.manager.controller;

import com.tyxy.edu.info.manager.domain.Student;
import com.tyxy.edu.info.manager.service.StudentService;

import javax.swing.*;
import java.util.Scanner;

public class StudentController {

    public void start() {
        studentloop:while (true){
        Scanner sc=new Scanner(System.in);
        System.out.println("------欢迎来到学生管理系统------");
        System.out.println("请输入您的选择 1.添加学生 2.删除学生 3.修改学生 4.查询学生 5.退出");
        String choice = sc.next();
        switch (choice){
            case "1":
                System.out.println("添加");
                addstudent();
                break;
            case "2":
                System.out.println("删除");
                break;
            case "3":
                System.out.println("修改");
                break;
            case "4":
                System.out.println("查询");
                break;
            case "5":
                System.out.println("感谢您使用学生管理系统，再见!");
                break studentloop;
            default:
                System.out.println("您的输入有误");
        }
    }
    }

   public void addstudent() {
        StudentService studentService=new StudentService();
        Scanner sc=new Scanner(System.in);
       String id;
        while (true){
            System.out.println("请输入学生id");
        id=sc.next();
            boolean flag=studentService.isExists(id);
            if(flag){
                System.out.println("学号已被占用，请重新输入");
            }
            else {
                break;
            }
        }

       System.out.println("请输入学生姓名");
       String name=sc.next();
        System.out.println("请输入学生年龄");
        String age=sc.next();
        System.out.println("请输入学生生日");
        String birthday=sc.next();
        Student student=new Student();
        student.getAge(age);
        student.getBirthday(birthday);
        student.getId(id);
        student.getName(name);

        boolean a=studentService.addstudent(student);
        if (studentService.addstudent(student)) a = true;
        else a = false;
        if(a){
            System.out.println("输入成功");
        }
        else {
            System.out.println("输入失败");

        }
}

    public void start2() {
        teacherloop:while (true){
            Scanner sc1=new Scanner(System.in);
            System.out.println("------欢迎来到老师管理系统------");
            System.out.println("请输入您的选择 1.添加老师 2.删除老师 3.修改老师 4.查询老师 5.退出");
            String choice = sc1.next();
            switch (choice){
                case "1":
                    System.out.println("请添加老师");
                    break;
                case "2":
                    System.out.println("请删除");
                    break;
                case "3":
                    System.out.println("修改");
                    break;
                case "4":
                    System.out.println("查询");
                    break;
                case "5":
                    System.out.println("感谢您使用老师管理系统，再见!");
                    break teacherloop;
                default:
                    System.out.println("您的输入有误");
            }
        }

    }
    }

